/**
 * 
 */
package soa.security.web.export;

import java.io.IOException;

import javax.naming.ldap.LdapName;

import v1.web.export.DefaultJsonFormatExport;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;

/**
 * @author Cre.Gu
 *
 */
public class LdapJsonFormatExport extends DefaultJsonFormatExport {

	public LdapJsonFormatExport(Object source) {
		super(source);
	}

	public LdapJsonFormatExport(Object source, ObjectMapper mapper) {
		super(source, mapper);
	}

	@Override
	protected void configExport(Object source, ObjectMapper mapper) {
		super.configExport(source, mapper);

		SimpleModule module = new SimpleModule();

		module.addSerializer(LdapName.class, new JsonSerializer<LdapName>() {
			@Override
			public void serialize(LdapName value, JsonGenerator jgen,
					SerializerProvider provider) throws IOException,
					JsonProcessingException {
				jgen.writeString(value.toString());
			}
		});

		mapper.registerModule(module);
	}

}
